const hello = (name: string) => {
    console.log(`hello, ${name}`);
};
hello("typescript");

/**
 * typescript 数据类型
 */
export {};

const a: string = "foo"; // null
const b: number = undefined; // 100 undefined Infinity
const d: boolean = true; // null
const e: void = undefined;
const f: null = null;
const g: undefined = undefined;

const h: symbol = Symbol();

const arr1: Array<number> = [1, 2, 3];
const arr2: number[] = [1, 2, 3];
function sum(...args: number[]): number {
    return args.reduce((total, item) => total + item, 0);
}
sum(1, 2, 3, 4);

// 元组
const foo: [number, string] = [11, "foo"];
const [age, name] = [11, "wlz"];

// 枚举类型 Enum
const enum postStatus {
    success, // 0
    danger, // 1
    warning, // 2
}

// const enum postStatus {
//     success = 'a',
//     danger = 'b',
//     warning = 'c',
// }

const post = {
    title: "sadasdas",
    content: "asdasdasdasdasd",
    status: postStatus.success,
};

// 任意类型 any

//隐式类型推断
// let ages = 100
// ages = 'string'

// 类型断言
const nums = [1, 2, 3, 4, 5];
const res = nums.find(i => i > 0);
// const square = res * res  // Object is possibly 'undefined'
const num1 = res as number;
const num2 = <number>res; // JSX 下不可用

// interfaces 接口 约束一个对象的结构
interface Post {
    title: string;
    content: string;
    subtitle?: string;
    readonly summary: string;
}

function printPost(post: Post) {
    console.log(post.title);
    console.log(post.content);
}
printPost({
    title: "asdasd",
    content: "1231231asdas",
    summary: "412342asdasd",
});
const hello1: Post = {
    title: "asdasd",
    content: "1231231asdas",
    summary: "412342asdasd",
};
// hello1.summary = "other"; // readonly 只读


interface Cache {
    [prop:string]: string
}

let obj: Cache = {
    asd: '100'
}